package com.iris.live.services.data.repositories.impl;

import com.google.common.collect.Maps;
import com.iris.live.services.data.repositories.QueryTodayTodoListRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by ThinkPad on 2016/9/22.
 */
@Repository
public class QueryTodayTodoListRepositoryImpl extends BaseRepository implements QueryTodayTodoListRepository {
    @Override
    public List getLSHtodoList(String startDate,String endDate,String permit ) {
        String sql = "SELECT b.`人员姓名`,IF(a.`附属编号类型` = '线索', c.`顾客姓名`, IF(a.`附属编号类型` = '顾客', d.`顾客姓名`, '')) 顾客姓名,\n" +
                "IF(a.`附属编号类型` = '线索', c.`电话号码`, IF(a.`附属编号类型` = '顾客', d.`电话号码`, '')) 顾客电话,a.`开始时间`,a.`结束时间`,a.`待办分类`,a.`内容` \n" +
                "FROM `LSH待办事项` AS a \n" +
                "INNER JOIN `用户` AS b ON b.`用户名` = a.`销售顾问` AND b.`许可` = a.`许可` AND b.`角色` = '销售顾问' AND b.`删除状态` <> '已删除' \n" +
                "LEFT JOIN `LSH导入名单` AS c ON c.`许可` = a.`许可` AND c.`导入编号` = a.`附属编号` \n" +
                "LEFT JOIN `顾客记录汇总` AS d ON d.`许可` = a.`许可` AND d.`顾客编号` = a.`附属编号` \n" +
                "WHERE a.`开始时间` >= :startDate AND a.`结束时间` < :endDate AND a.`许可` =:permit AND a.`是否删除` = '否' \n" +
                "ORDER BY a.`开始时间` DESC, a.`结束时间` DESC";
        Map params = Maps.newHashMap();
        params.put("permit", permit);
        params.put("startDate",startDate);
        params.put("endDate",endDate);
        return this.getList(sql, params);
    }
}
